package ui;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.border.LineBorder;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;

import com.sun.tools.javac.util.Name.Table;

import net.miginfocom.swing.MigLayout;

/**
 * @author clementj
 */
public class MainWindow extends JFrame {
	
	private static final long serialVersionUID = 1L;
	
	private JTabbedPane tabbedPane;
	private Resources resources;
	
	private JButton btnCreate;
	private JButton btnDelete;
	
	private JTable table;
		
	public MainWindow () {
		setSize(1024, 768);
		initUI();
	}

	private void initUI() {
		resources = Resources.getInstance();
		setTitle(resources.getString("title.app") +" "+resources.getString("misc.separator")+" "+resources.getString("title.copyright"));
	
		setContentPane(createContentPanel());
	}

	/**
	 * @return
	 */
	private JPanel createContentPanel() {
		JPanel panel = new JPanel(new MigLayout("fill, wrap 1", "[fill, grow]", "[fill, grow]"));
		
		tabbedPane = new JTabbedPane();
		// TODO : setup a tab icon.
		tabbedPane.addTab(resources.getString("title.tab.ports"), createPortTab());
		tabbedPane.addTab(resources.getString("title.tab.connections"), createConnectionsTab());
		
		panel.add(tabbedPane);
		
		return panel;
	}

	private Component createConnectionsTab() {
		return new JPanel();
	}

	private Component createPortTab() {
		JPanel panel = new JPanel(new MigLayout("fill, debug 100, wrap 1", "[center, fill, grow]", "[][fill, grow]"));
		
		panel.add(createTableActionPanel());
		panel.add(createTable());
		
		return panel;
	}
		

	private Component createTable() {
		table  = new JTable(new VMidiTableModel());
		return new JScrollPane(table);
	}

	private Component createTableActionPanel() {
		JPanel panel = new JPanel(new MigLayout("fill, debug 100, insets 8", "[][][fill, grow]"));
		
		panel.setBackground(new Color(109, 207, 246));
		panel.setBorder(new LineBorder(new Color(0,0,0)));
		
		// Buttons.
		btnCreate = new JButton(resources.getString("label.create"));
		btnDelete = new JButton(resources.getString("label.delete"));
		
		panel.add(btnCreate);
		panel.add(btnDelete);
		
		return panel;
	}
}
